package com.ignitetest.datanode;

import org.apache.ignite.Ignition;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;

import java.util.*;

/**
 * Created by User on 2017/5/12.
 */
public class DataNodeServer2 {
    public  static void main(String[] args) {
// Preparing cache configuration.
        CacheConfiguration cacheCfg = new CacheConfiguration<>("personCache");
// Creating the query entity.
        QueryEntity entity = new QueryEntity("CustomKey", "Person");
// Listing all the queryable fields.
        LinkedHashMap<String, String> flds = new LinkedHashMap<>();
        flds.put("id", String.class.getName());
        flds.put("firstName", String.class.getName());
        flds.put("lastName", String.class.getName());
        entity.setFields(flds);
// Listing a subset of the fields that belong to the key.
        Set<String> keyFlds = new HashSet<>();
        keyFlds.add("id");
        entity.setKeyFields(keyFlds);
// End of new settings, nothing else here is DML related
        entity.setIndexes(Collections.<QueryIndex>emptyList());
        cacheCfg.setQueryEntities(Collections.singletonList(entity));

        // Create new configuration.
        IgniteConfiguration cfg = new IgniteConfiguration();
        cfg.setCacheConfiguration(cacheCfg);


        TcpDiscoveryMulticastIpFinder ipFinder =new TcpDiscoveryMulticastIpFinder();
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47509"));
        TcpDiscoverySpi tcpDiscoverySpi =new TcpDiscoverySpi();
        tcpDiscoverySpi.setIpFinder(ipFinder);
        cfg.setDiscoverySpi(tcpDiscoverySpi);
        // Start Ignite node with given configuration.
       Ignition.start(cfg);
    }
}
